Skip to content

Conversation

@EmilHvitfeldt
Copy link
Member

This PR adds a new exported internal function condense_control(). This function takes 2 argument, which should be 2 control_*() objects. It turns the first control object into the same class as the second object if the elements required exists, otherwise it throws an error.

This PR will be accompanied with PR it other tidymodels packages that create or use control_*() objects. These PRs will mostly backfill missing arguments so that all the hierarchy is preserved

library(parsnip)
library(finetune)

str(control_resamples())
#> List of 8
#>  $ verbose      : logi FALSE
#>  $ allow_par    : logi TRUE
#>  $ extract      : NULL
#>  $ save_pred    : logi FALSE
#>  $ pkgs         : NULL
#>  $ save_workflow: logi FALSE
#>  $ event_level  : chr "first"
#>  $ parallel_over: NULL
#>  - attr(*, "class")= chr [1:2] "control_grid" "control_resamples"
str(control_race())
#> List of 13
#>  $ verbose      : logi FALSE
#>  $ verbose_elim : logi FALSE
#>  $ allow_par    : logi TRUE
#>  $ extract      : NULL
#>  $ save_pred    : logi FALSE
#>  $ alpha        : num 0.05
#>  $ burn_in      : num 3
#>  $ num_ties     : num 10
#>  $ randomize    : logi TRUE
#>  $ pkgs         : NULL
#>  $ save_workflow: logi FALSE
#>  $ parallel_over: chr "everything"
#>  $ event_level  : chr "first"
#>  - attr(*, "class")= chr "control_race"

ctrl <- condense_control(
  control_race(verbose = TRUE), 
  control_resamples()
)

str(ctrl)
#> List of 8
#>  $ verbose      : logi TRUE
#>  $ allow_par    : logi TRUE
#>  $ extract      : NULL
#>  $ save_pred    : logi FALSE
#>  $ pkgs         : NULL
#>  $ save_workflow: logi FALSE
#>  $ event_level  : chr "first"
#>  $ parallel_over: chr "everything"
#>  - attr(*, "class")= chr [1:2] "control_grid" "control_resamples"

condense_control(
  control_resamples(),
  control_race(verbose = TRUE)
)
#> Error in `condense_control()`:
#> ! Object of class `control_grid` cannot be corresed to object of class `control_race`.
#> • The following arguments are missing:
#> • 'verbose_elim', 'alpha', 'burn_in', 'num_ties', and 'randomize'

Copy link
Member

@topepo topepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make similar changes to finetune?

@topepo topepo merged commit 00cd2c2 into main Sep 15, 2022
@EmilHvitfeldt
Copy link
Member Author

here: tidymodels/finetune#47

@topepo topepo deleted the control_control branch September 15, 2022 18:55
@github-actions
Copy link
Contributor

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants